import { WEATHER_TYPES } from '../config/gameConfig'

export const weatherSystem = {
  currentWeather: {
    type: 'sunny',
    temp: 25,
    description: '晴天'
  },

  weatherTypes: ['sunny', 'cloudy', 'rain', 'storm'],
  
  weatherEffects: {
    sunny: { growth: 1.2, water: -0.2 },
    cloudy: { growth: 1.0, water: 0 },
    rain: { growth: 1.1, water: 0.2 },
    storm: { growth: 0.8, water: 0.3 }
  },

  updateWeather() {
    const random = Math.random()
    let newType
    
    if (random < 0.4) {
      newType = 'sunny'
    } else if (random < 0.7) {
      newType = 'cloudy'
    } else if (random < 0.9) {
      newType = 'rain'
    } else {
      newType = 'storm'
    }
    
    this.currentWeather = {
      type: newType,
      temp: this.generateTemperature(newType),
      description: this.getWeatherDescription(newType)
    }
    
    return this.currentWeather
  },

  generateTemperature(weatherType) {
    const baseTemp = 25
    const variation = Math.random() * 10 - 5
    
    switch (weatherType) {
      case 'sunny':
        return Math.round(baseTemp + variation + 5)
      case 'cloudy':
        return Math.round(baseTemp + variation)
      case 'rain':
        return Math.round(baseTemp + variation - 3)
      case 'storm':
        return Math.round(baseTemp + variation - 5)
      default:
        return Math.round(baseTemp + variation)
    }
  },

  getWeatherDescription(type) {
    const descriptions = {
      sunny: '晴天',
      cloudy: '多云',
      rain: '下雨',
      storm: '暴风雨'
    }
    return descriptions[type] || '晴天'
  },

  calculateGrowthModifier(crop) {
    const effect = this.weatherEffects[this.currentWeather.type]
    return effect ? effect.growth : 1.0
  }
} 